package library.operation;

import library.Book;
import library.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation {

    @Override
    public void work(BookList bookList) {
        //让用户输入新的书籍
        //然后把新书的书籍信息放到BookList中
        System.out.println("新增图书");
        Scanner scanner =new Scanner(System.in);
        System.out.print("请输入书名：");
        String bookName = scanner.nextLine();
        System.out.print("请输入作者：");
        String author = scanner.nextLine();
        System.out.println("请输入价格");
        double price = scanner.nextDouble();
        System.out.println("请输入类型");
        String type = scanner.next();
        //是否借出我们不输入 默认为false;
        Book book = new Book(bookName, author, price, type, false);
        //把新书添加到数组的最后一个位置
        //Book已经存在N本书l。
        //对应的下标为【0，n-1】
        //所以最后一个位置的下标为n
        //并且size+1；
        int size=bookList.getSize();
        bookList.setBook(size,book);
        bookList.setSize(size+1);
        System.out.println("图书添加成功！");

    }
}
